import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

const useLocaleStore = defineStore('locale', () => {
    const localeLabel = ref('zh-cn')
    function setLocale(label: string) {
        const localeList = ['zh-cn', 'zh-tw', 'en-us', 'en-gb', 'jpan']
        if (localeList.indexOf(label) > -1)
            localeLabel.value = label
        else throw Error('语言库不存在:' + label)
    }

    function getLocaleLabel() {
        return localeLabel.value
    }
    return {
        localeLabel, setLocale, getLocaleLabel
    }
})
export default useLocaleStore